import request from "@/utils/request";
import { AxiosPromise } from "axios";
import { UserForm, UserInfo, UserPageVO, UserQuery, UserRegister } from "./types";

/**
 * 新增用户带着机构注册
 * @param data
 */
export function addUser(data: any) {
  return request({
    url: "/stasx/user/register2org/v1",
    method: "post",
    data,
  });
}

/**
 * 用户名查询
 * @param queryParams
 */
export function getUserAddPage(queryParams: any) {
  return request({
    url: "/stasx/user/list4add/v1",
    method: "get",
    params: queryParams,
  });
}

/**
 * 添加用户
 * @param data
 */
export function addUserAndAccount(data: any) {
  return request({
    url: "/stasx/user/add2org/v1",
    method: "post",
    data,
  });
}

/**
 * 修改用户
 *
 * @param id
 * @param data
 */
export function updateUser(data: any) {
  return request({
    url: "/stasx/user/update/v1",
    method: "post",
    data: data,
  });
}

/**
 * 重置密码
 * @param data
 */
export function updateResetPwd(data: any) {
  return request({
    url: "/stasx/user/resetPwd/v1",
    method: "post",
    data: data,
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
  });
}

/**
 * 获取用户分页列表
 *
 * @param queryParams
 */
export function getUserPage(queryParams: UserQuery): AxiosPromise<PageResult<UserPageVO[]>> {
  return request({
    url: "/stasx/user/list/v1",
    method: "get",
    params: queryParams,
  });
}

/**
 * 配置用户是否是领导
 * @param data
 */
export function configLeader(data: any) {
  return request({
    url: "/stasx/user/configLeader/v1",
    method: "post",
    data,
  });
}

/**
 * 将用户从系统中删除
 * @param ids
 */
export function deleteFromSystem(data: any) {
  return request({
    url: "/stasx/user/deleteFromSystem/v1",
    method: "delete",
    data: data,
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
  });
}

/**
 * 将用户从机构中删除
 * @param ids
 */
export function deleteFromOrg(data: any) {
  return request({
    url: "/stasx/user/deleteFromOrg/v1",
    method: "delete",
    data: data,
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
  });
}

/**
 * 登录成功后获取用户信息（昵称、头像、权限集合和角色集合）
 */
export function getUserInfoApi(): AxiosPromise<UserInfo> {
  return request({
    url: "/v1/users/me",
    method: "get",
  });
}
